<?php

/*
	backup.php -- make a backup of docman site using mass downloader

	Dobrica Pavlinusic <dpavlin@rot13.org>
	v0.0 2001-05-25

	Usage:

	rename this script to .backup.php in same dir where .index.php is

	$ wget -r -np http://docman.site.com/.backup.php?secret

	where "secret" is password defined below!

*/


// change this to password
$password="secret";

$dir=dirname($SCRIPT_FILENAME);
$dir_len=strlen($dir)-strlen(dirname($SCRIPT_NAME));


//////////////////////////////////////////////////////////////////

function urlpath($url) {
	$url=urlencode(StripSlashes("$url"));
	$url=str_replace("%2F","/",$url);
	$url=str_replace("+","%20",$url);
	return($url);
}

//////////////////////////////////////////////////////////////////


print "<html>
<head>
<title>backup docman site</title>
</head>
<body>";

if ($QUERY_STRING != $password) {
	print "you are not allowed to do backup!";
} else {

	print "<h1>Files to backup:</h1><ul>";

	$dirs = array( $dir );

	while ($dirs) {

		$dir=array_shift($dirs);
		$handle=opendir($dir);
		while ($file = readdir($handle)) {
			if (substr($file,0,1) != ".") {
				if (is_dir("$dir/$file"))
					array_push($dirs,"$dir/$file");
				else
					$url=urlpath(substr("$dir",$dir_len,strlen($dir)-$dir_len)."/$file");
					if ($url != "") {
						print "<li><a href=\"$url\">$url</a> [$dir/$file]\n";
					}
			}
		}
		closedir($handle);
	}

	print "</ul>";
}

print "
</body>
</html>
";
